package ynu.edu.achitectureclass.Schedule;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.beans.factory.annotation.Autowired;
import ynu.edu.achitectureclass.controller.*;
import ynu.edu.achitectureclass.controller.AirSensorController.Air_temp_Controller;
import ynu.edu.achitectureclass.controller.AirSensorController.Air_water_Controller;
import ynu.edu.achitectureclass.controller.SoilSensorController.*;

@Component // 将类标记为 Spring 组件
public class ScheduledTasks {

    @Autowired
    private Soil_L_Controller soil_L_Controller;
    @Autowired
    private Soil_N_Controller soil_N_Controller;
    @Autowired

    private Soil_K_Controller soil_K_Controller;
    @Autowired
    private Air_temp_Controller air_temp_Controller;
    @Autowired
    private Air_water_Controller air_water_Controller;
    @Autowired
    private SoilWaterController soilWater_Controller;
    @Autowired
    private SoilTemperatureController soilTemperature_Controller;
    @Autowired
    private CameraDataController cameraDataController;

    private int executionCount = 0; // 计数器
    // 每 10 分钟执行一次
    @Scheduled(fixedRate = 1800000) // 600000 毫秒 = 10 分钟
    public void executeTasks() {
        executionCount++; // 每次调用时递增计数器
        System.out.println("这是第 " + executionCount + " 次调用");

        // 调用 Controller 中的方法
        soil_L_Controller.getSoilData("Soil_L");
        soil_N_Controller.getSoilData("Soil_N");
        soil_K_Controller.getSoilData("Soil_K");
        soilWater_Controller.getSoilData("SoilWater");
        soilTemperature_Controller.getSoilData("SoilTemperature");
        air_temp_Controller.getSoilData("Air_temp");
        air_water_Controller.getSoilData("Air_water");
        cameraDataController.captureImage();

        System.out.println();
    }
}